package com.xx.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xx.common.constant.BridgeAlarm;
import com.xx.system.mapper.SysBridgeAlarmMapper;
import com.xx.system.service.ISysBridgeAlarmService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * TODO
 * 桥梁接收报警信息服务实现类
 * @Author kzw
 * @Date 2025/4/2 14:03
 */
@Service
public class SysBridgeAlarmServiceImpl extends ServiceImpl<SysBridgeAlarmMapper, BridgeAlarm> implements ISysBridgeAlarmService {

/*    @Override
    public boolean syncBridgeAlarmInfo(BridgeAlarm bridgeAlarm, String token) {
        return saveOrUpdate(bridgeAlarm);
        // 验证token是否有效
        if (JWTUtil.verifyToken(token)) {
            // 如果token验证通过，则执行插入或更新操作
            return saveOrUpdate(bridgeAlarm); // 使用MyBatisPlus的saveOrUpdate方法
        } else {
            // 如果token无效，返回false
            return false;
        }
    }*/

    /*@Override
    public boolean syncBridgeAlarmInfo(List<BridgeAlarm> bridgeAlarms, String token) {
        try {
            for (BridgeAlarm alarm : bridgeAlarms) {
                // 设置创建时间
                alarm.setCreateTime(new Date());
                // 转换时间戳为Date类型
                if (alarm.getAlarmStartTime() != null) {
                    alarm.setAlarmStartTime(alarm.getAlarmStartTime());
                }
                if (alarm.getAlarmEndTime() != null) {
                    alarm.setAlarmEndTime(alarm.getAlarmEndTime());
                }
                if (alarm.getConfirmTime() != null) {
                    alarm.setConfirmTime(alarm.getConfirmTime());
                }
                if (alarm.getHandleTime() != null) {
                    alarm.setHandleTime(alarm.getHandleTime());
                }
            }
            // 批量保存或更新数据
            return saveBatch(bridgeAlarms);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }*/

    @Override
    public boolean syncBridgeAlarmInfo(List<BridgeAlarm> bridgeAlarms) {
        try {
            for (BridgeAlarm alarm : bridgeAlarms) {
                // 设置创建时间
                alarm.setCreateTime(new Date());
            }
            // 批量保存或更新数据
            return saveBatch(bridgeAlarms);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
